package com.example.backend.controller;

import com.example.backend.pojo.Food;
import com.example.backend.pojo.Result;
import com.example.backend.service.FoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/food")
public class FoodController {
    @Autowired
    private FoodService foodService;

//    获得该商家的所有菜品
    @PostMapping("/getall")
    public Result<List<Food>> getall(Integer restaurantid){
        List<Food> foods=foodService.getall(restaurantid);
        return Result.success(foods);
    }

    //增加菜品
    @PutMapping("/add")
    public Result add(@RequestBody Food food){
        foodService.add(food);
        return Result.success();
    }
    // 对某一菜品进行修改
    @PatchMapping("/update")
    public  Result update(@RequestBody Food food){
        foodService.update(food);
        return Result.success();
    }
    //菜品下架
    @PostMapping("/delete")
    public Result delete(Integer foodid){
        foodService.delete(foodid);
        return  Result.success();
    }
    //菜品转态恢复
    @PostMapping ("/relive")
    public Result relive(Integer foodid){
        foodService.relive(foodid);
        return  Result.success();
    }
    @PostMapping("/getallcommend")
    public Result<List<Food>> getallcommend(String restaurantid){

        return  Result.success(foodService.getallcommend(restaurantid));
    }

    @PostMapping("/updatecommend")
    public Result updatecommend(Integer commend,String foodid){

        foodService.updatecommend(commend,foodid);
        return  Result.success();
    }

}
